// Pages/personalData/personalData.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    headPhoto:'../../images/head.jpg',
    account:'',
    userName:'',
    phoneNumber:'',
    wechat:'',
    yuanxi:'',
    classNumber:'',
    alldata:[]

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.loadData();
    var token=wx.getStorageSync('token')
    wx.request({
      url: 'http://47.103.21.65:5645/user/getSystemMessage',
      method:'POST',
    
      data:{
          page:1
      },
      header:{
        'content-type': 'application/x-www-form-urlencoded',
        'token':token
      }
      ,
      success:function(res){
        console.log(res)
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  loadData:function(){
    var that=this;
    var to = wx.getStorageSync("token");
    console.log(to)
    wx.request({
      url: 'http://47.103.21.65:5645/user/userInfo',

      method: "POST",

      data: {  //参数传递
       
      },
      header: { //设置请求头
        'content-type': 'application/x-www-form-urlencoded',// 默认值//header:{...}用啥设置啥，
        'token':to
      },
      success: function (res) {
        console.log(res)
       that.setData({
         headPhoto: res.data.data.info.photo,
         account:res.data.data.info.account,
         userName: res.data.data.info.name,
         phoneNumber: res.data.data.info.mobile,
         wechat: res.data.data.info.weixin,
         yuanxi: res.data.data.info.department,
         classNumber: res.data.data.info.grade,

         alldata:res.data.data.info

       })

      },
      fail: function (error) { //请求失败
        console.log(error);

      }
    })
  },
  chooseHead:function(){
    let data=''
    let names=''
    var token=wx.getStorageSync('token')
    var that=this
    wx.chooseImage({
      count:1,

      success: function(res) {
        data = res.tempFilePaths[0];
        console.log(data)
        wx.uploadFile({
          url: 'http://47.103.21.65:5645/user/updatePhoto',
          filePath: data,
          name: 'image',
          header: {
            "Content-Type": "multipart/form-data",
            'token': token
          },
          success: function (res) {
            console.log(res)
            that.loadData();
            
          }
        })
      },
      fail:function(res){
        wx.showToast({
          title: '失败',
          icon:'none'
        })
      }
    })

  
  },
  outofload:function(){
    
    wx.clearStorageSync("token")
    wx.showToast({
      title: '退出成功',
      icon:'none'
    })
    setTimeout(function (){
      wx.navigateBack({
        delta: 1
      })
    },1000)
    
  },
  change:function(e){
    var that=this
    let id = e.currentTarget.dataset.identif
    let all=JSON.stringify(that.data.alldata)
    console.log(e)
    wx.navigateTo({
      url: '../changemyinfo/changemyinfo?id='+id+"&alldata="+all,
    })
  }
})
